﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;

namespace ResponseMonitor
{
    public class ESData
    {
        public List<DeviceData> Device = new List<DeviceData>();
        public List<StartupInfoData> StartupInfo = new List<StartupInfoData>();
        //public List<ObjectData> Object = new List<ObjectData>();
        public Hashtable Object = new Hashtable();

        public ESData()
        {
        }
    }

    public class DeviceData
    {
        public int _VersionPersist;
        public int OpenDevice;
        public int Width;
        public int Height;
        public int Bpp;
        public string Name;
        public string Class;

        public DeviceData()
        { }
    }

    public class StartupInfoData
    {
        public StartupInfoData()
        { }
    }

    public class ObjectData
    {
        public string Name = string.Empty;

        public string OriginalContent = string.Empty;

        public ObjectData(string s)
        {
            this.OriginalContent = s;
            _process();
        }

        private void _process()
        {
            Regex r = new Regex("\r\n", RegexOptions.Multiline);
            string[] ss = r.Split(OriginalContent);

            //  Parse "Name"
            foreach (string s in ss)
            {
                if (s.StartsWith("Name="))
                {
                    string ri = s.Split('=')[1];
                    this.Name = ri.Substring(1, ri.Length - 2);
                    break;
                }
            }

            if (this.Name.Length == 0)
                throw new Exception("the object does not have NAME property");
        }
    }
}
